﻿/* Filename: Demon.as 
 *
 * Description: This class creates demons
 * that belong to player1 or player2.  It
 * also stores the map location of the demon
 * and a unique ID for determining if this
 * is a particular demon.
 *
 * Tyler Samson
 * Feb 2008
 * @ Sierra Nevada College
 */
 class Demon extends DemonTemplate {
	private var _uniqueId:String;				// unique identifier of this demon
	private var _owner:Player;					// owner of this demon
	private var _demonLocationX:Number;			// x location of demon in tiles
	private var _demonLocationY:Number;			// y location of demon in tiles
	private var _demonMovement:Number;			// number of spaces a demon can move
	
	public function Demon(p_demonTemplate:DemonTemplate, p_uniqueId:String,
							p_demonLocationX:Number, p_demonLocationY:Number) {
		
		super(p_demonTemplate.getName(), p_demonTemplate.getElementType(),
				p_demonTemplate.getHealth(), p_demonTemplate.getAttacks(), p_demonTemplate.getTerrainAttacks());	// Set this demon's basic features to match the template it is following
		_uniqueId = p_uniqueId;
		_demonLocationX = p_demonLocationX;
		_demonLocationY = p_demonLocationY;
		_demonMovement = 1;
	}
	
	// Change health by number passed in
	public function changeHealth(p_healthChange:Number):Void {
		_health = _health + p_healthChange;
	}
	
	// Return the Demon's health
	public function getHealth():Number {
		return _health;
	}
	
	// Return X location
	public function getX():Number {
		return _demonLocationX;
	}
	
	// Return Y location
	public function getY():Number {
		return _demonLocationY;
	}
	
	public function getMovement():Number {
		return _demonMovement;
	}
	
	// Return this demon's owner
	public function getOwner():Player {
		return _owner;
	}
	
	// Return this demon's unique identifier
	public function getUniqueId():String {
		return _uniqueId;
	}
	
	// Set the X location on the map of this demon
	public function setX(p_newX:Number) {
		_demonLocationX = p_newX;
	}
	
	// Set the Y location on the map of this demon
	public function setY(p_newY:Number) {
		_demonLocationY = p_newY;
	}
	
	public function setMovement(p_movement:Number) {
		_demonMovement = p_movement;
	}
	
	// Set the owner of this demon
	public function setOwner(p_owner:Player) {
		_owner = p_owner;
	}
	
	// Compare this demon to another demon
	public function compareTo(p_demon:Demon):Boolean {
		var returnValue:Boolean = false;
		
		if (getUniqueId() == p_demon.getUniqueId() &&
				getOwner() == p_demon.getOwner()) {
			returnValue = true;
		}
		
		return returnValue;
	}
}
